#!/bin/sh

echo "======> run FE's build procedure start <======"
startTime=`date "+%s"`

echo "remove node_modules folder"
rm -rf ./node_modules

yarn install
if [ $? == 1 ] ;then
    echo "install dependencies failed"
    exit 1
fi

./node_modules/.bin/sfe-service build $1
if [ $? == 1 ] ;then
    echo "build failed"
        exit 1
    fi
chmod -R 777 ./dist/

#编译完成，所有文件已放到项目的dist目录下，删除在过程中可能引入的.git隐藏文件夹
find dist -type d -name ".git" -exec rm -r {} \;

rc=$?; if [[ $rc == 1 ]]; then exit $rc; fi
rm -fr ./node_modules
endTime=`date "+%s"`
cost=$[$endTime-$startTime]
echo " ------------------------------------------------------------------------"
echo "  FE's BUILD SUCCESS"
echo " ------------------------------------------------------------------------"
echo "  Total time: ${cost}s"
echo "  Finished at: `date '+%Y-%m-%d %H:%M:%S'`"
echo " ------------------------------------------------------------------------"
echo "======> run FE's build procedure end <======"
